home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM B4 / PD-ROM B4.iso / Entertainment / Strategy / Robots / bot 1.0.1 / Tutorial / ASM / Middle < prev    next >
Text File  |  1991-06-25  |  6KB  |  286 lines

  1. !
  2. ! Middle
  3. !
  4. ! This bot uses a number of the more advanced design options,
  5. ! including intelligent damage recognition and a repair
  6. ! mechanism.  It takes advantage of the fact that from the
  7. ! middle of the arena you are always scanning at a fairly close
  8. ! distance, so it's more likely that a given scan will find an
  9. ! enemy bot (Which means you want a very wide scan increment
  10. ! when scanning in a circle).
  11.  
  12.  
  13. #DATA
  14.  
  15. EQU INCR        37
  16. EQU FIND_INCR   11
  17.  
  18. DEF SCAN
  19. DEF D
  20. DEF DAMAGE_LOC
  21. DEF TEMP
  22. DEF CPUTHRESH
  23. DEF FIRST_TIME
  24.  
  25. #CODE ASM
  26.     
  27.     MOV A1, CPUTHRESH   ! If CPU < 1/2 MAXCPU, then the repair
  28.     DIV 2, CPUTHRESH    ! mechanism might jam.  Therefore,
  29.                         ! don't use it to time movements.
  30.     
  31.     MOV D0, D
  32.     JMP RUNAWAY_START   ! Move to center
  33.     
  34. :START
  35.     MOV D0, D
  36.     RND 360, SCAN
  37.     
  38. :SCANLOOP
  39.     CMP D0, D
  40.     BNE GOT_HIT
  41.     ADD INCR, SCAN
  42.     SCN SCAN
  43.     CMP S0, 0
  44.     BEQ SCANLOOP
  45. :SCANLOCK
  46.     MOV S1, R1
  47.     FIR 1
  48.     CMP D0, D
  49.     BNE GOT_HIT
  50.     SCN S1                  ! Center the scanner on the enemy
  51.     CMP S0, 0
  52.     BNE SCANLOCK            ! If we lost the lock, continue on
  53.  
  54. :LOCKON                     ! Try to locate the moving enemy
  55.     MOV SCAN, TEMP
  56.     SUB 43, TEMP
  57.  
  58.     SCN TEMP
  59.     CMP S0, 0
  60.     BNE SCANLOCK
  61.     ADD FIND_INCR, TEMP
  62.     SCN TEMP
  63.     CMP S0, 0
  64.     BNE SCANLOCK
  65.     ADD FIND_INCR, TEMP
  66.     
  67.     CMP D0, D               ! In case we've been hit
  68.     BNE GOT_HIT
  69.     
  70.     SCN TEMP
  71.     CMP S0, 0
  72.     BNE SCANLOCK
  73.     ADD FIND_INCR, TEMP
  74.     SCN TEMP
  75.     CMP S0, 0
  76.     BNE SCANLOCK
  77.     
  78.     JMP SCANLOOP            ! Couldn't find him.
  79.  
  80. ! These routines are called if damage is taken while we're
  81. ! sitting in the center of the arena.  Calls to the REPAIR
  82. ! mechanism are used to time the movement (and they repair the
  83. ! CPU if it gets damaged).  The bot will basically make a loop
  84. ! and go back into the middle.
  85.  
  86. :GOT_HIT
  87.     VEL 220, 70             ! Start running immediately
  88.     MOV D2, DAMAGE_LOC
  89.     CMP A1, CPUTHRESH
  90.     BLT GOT_HIT2
  91.     RPR 0, 2                ! Repair System 0 (the CPU) for 20
  92.     VEL -70, -220
  93.     RPR 0, 2                ! Repair some more
  94.     MOV D0, D
  95.     JMP RUNAWAY_START
  96.  
  97. :GOT_HIT2                   ! If CPU has been damaged
  98.     NOP
  99.     NOP                     ! If the repair mechanism jams due
  100.     NOP                     ! to the damaged CPU, we might keep
  101.     NOP                     ! repairing as we moved right into
  102.     NOP                     ! a wall!  Don't take that chance.
  103.     NOP
  104.     NOP
  105.     NOP
  106.     NOP
  107.     NOP
  108.     NOP
  109.     NOP
  110.     NOP
  111.     NOP
  112.     NOP
  113.     NOP
  114.     NOP
  115.     NOP
  116.     NOP
  117.     NOP
  118.     VEL -40, -150
  119.     RPR 0, 2                    
  120.     VEL 0, 0
  121.     MOV D0, D
  122.  
  123.  
  124. ! Move to the center of the arena.  If you get hit, go to the
  125. ! appropriate DAMAGE routine, below.  This is the same basic
  126. ! movement routine used by the previous bots, except that it
  127. ! checks for damage.
  128.  
  129. :RUNAWAY_START
  130.     RND 360, R1
  131. :RUNAWAY_X
  132.     CMP D0, D
  133.     BNE X_DAMAGE
  134. :CONTINUE_X
  135.     MOV 128, TEMP
  136.     SUB X0, TEMP
  137.     MUL 4, TEMP
  138.     VEL TEMP, 0
  139.     FIR 1                   ! Fire while moving.  Why not?
  140.     CMP X0, 136             ! After all, you might hit someone.
  141.     BGT RUNAWAY_X
  142.     CMP X0, 120
  143.     BLT RUNAWAY_X
  144.     VEL 0, 0
  145.  
  146. :RUNAWAY_Y
  147.     CMP D0, D
  148.     BNE Y_DAMAGE
  149. :CONTINUE_Y
  150.     MOV 128, TEMP
  151.     SUB Y0, TEMP
  152.     MUL 4, TEMP
  153.     VEL 0, TEMP
  154.     FIR 1
  155.     CMP Y0, 136
  156.     BGT RUNAWAY_Y
  157.     CMP Y0, 120
  158.     BLT RUNAWAY_Y
  159.     VEL 0, 0
  160.     
  161.     ADD 1, FIRST_TIME
  162.     CMP FIRST_TIME, 1       ! Don't do the following routine
  163.     BEQ START               ! the first time we move.
  164.     
  165. ! Use the Damage Recognition System:  The general direction of
  166. ! the shot that hit us is now stored in DAMAGE_LOC (it was in
  167. ! D2, but DAMAGE_LOC got a copy of it right after we started to
  168. ! run away).  That value is accurate (roughly) within 45
  169. ! degrees.  So, start scanning 45ish degrees less than that
  170. ! value and try to find your attacker.
  171.     
  172.     MOV D0, D
  173.     RND 4, SCAN
  174.     ADD DAMAGE_LOC, SCAN
  175.     ADD 43, DAMAGE_LOC      ! Go back to regular scanning if it
  176.     SUB 47, SCAN            !  gets about 90 past the beginning
  177.     SUB FIND_INCR, SCAN     ! (We add this right back (below))
  178. :FIND_SCANLOOP
  179.     CMP SCAN, DAMAGE_LOC
  180.     BGT START
  181.     CMP D0, D
  182.     BNE GOT_HIT
  183.     ADD FIND_INCR, SCAN
  184.     SCN SCAN
  185.     CMP S0, 0
  186.     BEQ FIND_SCANLOOP
  187. :FIND_SCANLOCK
  188.     MOV S1, R1
  189.     FIR 1
  190.     CMP D0, D
  191.     BNE GOT_HIT
  192.     SCN S1
  193.     CMP S0, 0
  194.     BNE FIND_SCANLOCK       ! If we lost the lock, go back to
  195.                             ! scanning normally
  196.     JMP START
  197.  
  198.  
  199. ! These routines are called if the bot takes damage while
  200. ! moving to the center of the arena.  They check to see if the
  201. ! damage was due to a collision (D1 == 4).  If not, then don't
  202. ! worry about it, as the enemy probably can't lock on to a
  203. ! moving target too well.  If so, then we bumped into someone.
  204. ! Scan for them and shoot if we find them.
  205.  
  206.  
  207. :X_DAMAGE
  208.     MOV D0, D
  209.     CMP D1, 4
  210.     BNE CONTINUE_X
  211. :X_TESTDIRECTION        ! Damage was from a collision
  212.     CMP X0, 130
  213.     BLT X_LESSTHAN      ! Are we moving left or right?
  214.     VEL 10, 0           ! (Back up slowly while firing)
  215.     MOV 150, SCAN
  216.     JMP X_SHOOT
  217. :X_LESSTHAN
  218.     VEL -10, 0
  219.     MOV -30, SCAN
  220. :X_SHOOT
  221.     SCN SCAN            ! Scan 30 away from the x-axis
  222.     CMP S0, 0
  223.     BNE X_QUICKSHOT
  224.     ADD 60, SCAN
  225.     SCN SCAN            ! Now scan 30 in the *other* direction
  226.     CMP S0, 0
  227.     BNE X_QUICKSHOT
  228.     SUB 30, SCAN
  229.     SCN SCAN            ! Finally, scan right along the x-axis
  230.     CMP S0, 0
  231.     BNE X_QUICKSHOT
  232.     MOV D0, D
  233.     JMP CONTINUE_X
  234.     
  235. :X_FIREAT
  236.     SCN S1              ! Center the scanner on the enemy
  237.     CMP S0, 0
  238.     BNE X_QUICKSHOT
  239.     MOV D0, D
  240.     JMP CONTINUE_X
  241. :X_QUICKSHOT
  242.     MOV S1, R1
  243.     FIR 1
  244.     JMP X_FIREAT
  245.  
  246. :Y_DAMAGE
  247.     MOV D0, D
  248.     CMP D1, 4
  249.     BNE CONTINUE_Y
  250. :Y_TESTDIRECTION        ! Damage was from a collision
  251.     CMP Y0, 130
  252.     BLT Y_LESSTHAN      ! Are we moving up or down?
  253.     VEL 0, 10
  254.     MOV 240, SCAN
  255.     JMP Y_SHOOT
  256. :Y_LESSTHAN
  257.     VEL 0, -10
  258.     MOV 60, SCAN
  259. :Y_SHOOT
  260.     SCN SCAN            ! Scan 30 away from the y-axis
  261.     CMP S0, 0
  262.     BNE Y_QUICKSHOT
  263.     ADD 60, SCAN
  264.     SCN SCAN            ! Now scan 30 in the *other* direction
  265.     CMP S0, 0
  266.     BNE Y_QUICKSHOT
  267.     SUB 30, SCAN
  268.     SCN SCAN            ! Finally, scan right along the y-axis
  269.     CMP S0, 0
  270.     BNE Y_QUICKSHOT
  271.     MOV D0, D
  272.     JMP CONTINUE_Y
  273.     
  274. :Y_FIREAT
  275.     SCN S1              ! Center the scanner on the enemy
  276.     CMP S0, 0
  277.     BNE Y_QUICKSHOT
  278.     MOV D0, D
  279.     JMP CONTINUE_Y
  280. :Y_QUICKSHOT
  281.     MOV S1, R1
  282.     FIR 1
  283.     JMP Y_FIREAT
  284.  
  285. #END
  286.